/**
 * @author: HenryDai
 * @Date: 2022/04/29 13:22
 * @description:
 */
public class VendingMachine {

    /**
     * 贩卖机状态
     */
    private State machineState;

    /**
     * 贩卖机商品剩余数量
     */
    private int goodCount;

    VendingMachine(int count){

        goodCount = count;
        if(goodCount>0)
        {
            machineState = new NoMoneyState();
        }
        else{
            machineState = new SoldOutState();
        }
    }

    /**
     * 投硬币
     */
    public void insertCoins()
    {
        this.machineState.insertCoins(this);
    }

    /**
     * 退钱
     */
    public void backCoins()
    {
        this.machineState.backCoins(this);
    }

    /**
     * 按键选物
     */
    public void pressButton()
    {
        this.machineState.pressButton(this);
    }

    /**
     * 发放物品
     */
    public void distributeGood()
    {
        this.machineState.distributeGood(this);
    }

    public void setState(State state)
    {
        machineState = state;
    }

    public int getGoodCount()
    {
        return goodCount;
    }

    public void setGoodCount(int count)
    {
        goodCount = count;
    }
}
